# import json
# import re
# import logging
#
# from QQLoginTool.QQtool import OAuthQQ
#
# from django.conf import settings
#
# logger = logging.getLogger('django')
# from django.contrib.auth import authenticate, logout
# from django.contrib.auth.backends import ModelBackend
# from django.http import JsonResponse
# from django.views import View
#
# from users.models import User
#
#
# class LoginView(View):
#     def post(self, request):
#         dict = json.loads(request.body)
#         username = dict.get('username')
#         password = dict.get('password')
#         remembered = dict.get('remembered')
#
#         if not all([username, password]):
#             return JsonResponse({'code': 400,
#                                  'errmsg': '缺少必要参数'})
#
#         user = authenticate(username=username, password=password)
#         if user is None:
#             return JsonResponse({'code': 400,
#                                  'errmsg': '账户或密码错误'})
#
#         if remembered != True:
#             request.session.set_expiry(0)
#         else:
#             request.session.set_expiry(None)
#
#         response = JsonResponse({'code': 0,
#                                  'errmsg': 'ok'})
#         response.set_cookie('username',
#                             user.username,
#                             max_age=None)
#         return response
#
#
# def get_user_by_count(account):
#     try:
#         if re.match(r'1[3-9]\d{9}$', account):
#             user = User.objects.get(mobile=account)
#         else:
#             user = User.objects.get(username=account)
#     except Exception as e:
#         logger.error(e)
#         return JsonResponse({'code': 400,
#                              'errmsg': '手机号或用户名输入错误'})
#     return user
#
#
# class MobileView(ModelBackend):
#     def authenticate(self, request, username=None, password=None, **kwargs):
#         user = get_user_by_count(username)
#         if user and user.check_password(password):
#             return user
#
#
# class LogooutView(View):
#     def delete(self, request):
#         logout(request)
#         response = JsonResponse({'code': 0,
#                                  'errmsg': 'ok'})
#         response.delete_cookie('username')
#         return response
#
#
# class QQFistView(View):
#     def get(self, request):
#         next = request.GET.get('next')
#
#         # 获取qq登录表页面
#         oauth = OAuthQQ(client_id=settings.QQ_CLIENT_ID,
#                         client_secret=settings.QQ_CLIENT_SECRET,
#                         redirect_uri=settings.QQ_REDITECT_URI,
#                         state=next)
#         # 调用对象获取请求地址
#         login_url = oauth.get_qq_url()
#
#         return JsonResponse({'code': 0,
#                              'errmsg': 'ok',
#                              'login_url': login_url})
#
#
# class QQUserView(View):
#     def get(self, request):
#         code = request.GET.get('code')
#         if not code:
#             return JsonResponse({'code': 400,
#                                  'errmsg': '缺少必要参数'})
#         oauth = OAuthQQ(client_id=settings.QQ_CLIENT_ID,
#                         client_secret=settings.QQ_CLIENT_SECRET,
#                         redirect_uri=settings.QQ_REDITECT_URI)
#         try:
#             access_token = oauth.get_access_token(code)
#             openid = oauth.get_access_token(access_token)
#         except Exception as e:
#             logger.error(e)
#             return JsonResponse({'code': 400,
#                                  'errmsg': '认证失败'})
#
#         pass
#
#
from django.views import View


class UersInfoView(loginRequiredMixin, View):
    '''用户中心'''

    def get(self, request):
        info_data = {'username': request.user.username,
                     'mobile': request.user.mobile,
                     'email': request.user.email,
                     'email_active': True}
